import request from '@/utils/request'
import type { ResponseData } from '@/types/common'
import type { Photographer, PhotographerQuery } from '@/types/photographer'

// 获取摄影师列表
export const getPhotographersList = (params?: {
  keyword?: string
  specialty?: string
  level?: number
  page?: number
  pageSize?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Photographer[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/users/photographers/list', {
    params: {
      keyword: params?.keyword || '',
      specialties: [params?.specialty],
      level: params?.level,
      page: params?.page || 1,
      pageSize: params?.pageSize || 10,
    },
  })
}

export const getAvailablePhotographersList = (params?: {
  level?: number
  shootingDate?: string
}) => {
  return request.get<{
    code: number
    data: {
      items: Photographer[]
    }
    message: string
  }>('/users/photographers/available', {
    params: {
      level: params?.level,
      shootingDate: params?.shootingDate,
    },
  })
}

// 创建摄影师用户
export const createPhotographer = (data: {
  username: string
  password: string
  nickname: string
  phone: string
  email: string
  photographer_info: {
    introduction?: string
    specialties: string[]
    level: number
  }
}) => {
  return request.post<ResponseData>('/users/photographer', data)
}

// 获取摄影师详情
export const getPhotographerDetail = (id: number) => {
  return request.get<{
    code: number
    data: Photographer
    message: string
  }>(`/users/photographer/${id}/detail`)
}

// 更新摄影师信息
export const updatePhotographer = (
  id: number,
  data: {
    username?: string
    nickname?: string
    phone?: string
    email?: string
    avatar?: string
    photographer_info: {
      introduction?: string
      specialties: string[]
      level: number
    }
  },
) => {
  return request.patch<ResponseData>(`/users/photographer/${id}/update`, data)
}

// 切换摄影师状态
export const togglePhotographerStatus = (id: number) => {
  return request.patch<ResponseData>(`/users/photographer/${id}/status`)
}
